package com.hippoframework.config;
import static com.hippoframework.config.ConfigConstants.DEFAULT_CONFIG_FILE;
import static com.hippoframework.config.ConfigConstants.DEFAULT_CONFIG_NAME;

import cn.hutool.core.io.resource.NoResourceException;
import cn.hutool.setting.dialect.Props;

/**
 * Environment注册者
 *
 * @author TylerW
 * @date 4/30/2020 3:41 PM
 */
public class EnvironmentRegistry {

    public static Environment createEnvironment() {
        Environment environment = new Environment();
        //加载默认配置(.properties)
        try {
            environment.addGenericProps(new GenericProps(Props.getProp(DEFAULT_CONFIG_FILE + ".properties"), PropsType.APP, DEFAULT_CONFIG_NAME));
        } catch (NoResourceException e) {
            throw new NoResourceException("无法找到默认配置文件，请在resources下创建" + DEFAULT_CONFIG_FILE + "文件");
        }
        //加载profile配置
        environment.loadProfile();

        return environment;
    }


}
